
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/head.ftl">
    <link href="/js/plugins/chosen/component-chosen.css" rel="stylesheet">
    <script src="/js/plugins/chosen/chosen.jquery.js"></script>
    <style>
        #ContentModal img{
            width: 100%;
        }
        #ContentModal .modal-body{
            overflow-x: auto;
            max-height: 500px;
        }
    </style>


    <script>
        $(function () {

            //点击添加按钮
            $("#addStrategyBtn").click(function(){
                $("#title").val( $("#strategySelect option:selected").text());
                $("#strategyId").val($("#strategySelect option:selected").val());
                $('#travelSelect').chosen({
                    /*没有搜索到匹配项时显示的文字*/
                    no_results_text: "没有相关的游记!",
                    /*少于 n 项时隐藏搜索框*/
                    disable_search_threshold: 10,
                });

                $("#strategyModal").modal("show");
            });
            //保存提示
            $("#editForm").ajaxForm(function(data){
                $.messager.confirm("提示","保存成功",function(){
                    window.location.reload();
                });
            });




            //查看文章
            $(".showContentBtn").click(function () {
                var id = $(this).data("id");
                $.get("/travel/getContent.do",{id:id},function(data){
                    console.log(data);
                    $("#ContentModal .modal-body").html(data.content);
                    $("#ContentModal").modal("show");
                })

            })
            //插件
            $('#strategySelect').chosen({
                no_results_text: "没有相关的攻略!",
                disable_search_threshold: 10,
            });


            //点击保存
            $("#saveBtn").click(function(){
                $("#editForm").submit();
            });
            
            //删除
            $(".deleteBtn").click(function () {
                var strategyId= $("#strategySelect option:selected").val();
                console.log(strategyId);
                var json =$(this).data("json")
                console.log(json.id);
                $.get("/strategyTravel/deleteRelation.do",{strategyId:strategyId,travelId:json.id},function (data) {
                    if (data.success) {
                        $.messager.confirm("提示","删除成功",function(){
                            window.location.reload();
                        });
                    }


                })
            })



        })
    </script>


</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu = "strategyTravel"/>
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">大家都在看</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyTravel/list.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>攻略搜索:</label>
                    <select id="strategySelect" name="strategyId" class="form-control form-control-chosen" data-placeholder="请选择所属攻略" >
                        <#list strategies as s>
                            <option value="${s.id}">${s.title}</option>
                        </#list>
                    </select>
                    <script>
                        $("select[name=strategyId]").val(${qo.strategyId!})
                    </script>
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="javascript:;" class="btn btn-success" id="addStrategyBtn">添加关联</a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                <tr>
                   <th>关联游记</th>
                </tr>

                </tr>

                <#list pageInfo.list as s>
                <#--遍历查询得到的每一个domain对象-->
                        <#list s.travel as d>
                            <tr>
                            <td>${(d.title)!}</td>

                            <td> <a href ="javascript:;" class="showContentBtn" data-id="${d.id}">查看文章</a></td>
                            <td>
                                <a href ="javascript:;" class="deleteBtn" data-json='${d.json}' >删除</a>
                            </td>
                            </tr>
                        </#list>


                </#list>

            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>


<#--查看文章-->
<div class="modal fade" id="ContentModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">游记内容</h4>
            </div>
            <div class="modal-body">

            </div>
        </div>
    </div>
</div>

<div id="strategyModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" enctype="multipart/form-data" action="/strategyTravel/insertRelation.do" style="margin: -3px 118px">
                    <input id="strategyId" type="hidden" name="strategyId" value="" />
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="" readonly >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">关联游记</label>
                        <div class="col-sm-6">
                            <select id="travelSelect" name="travelId" class="form-control form-control-chosen" data-placeholder="请选择关联的游记">
                            <#list travel as t>
                                <option value="${t.id}">${t.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>




</body>
</html>